package com.pand.model.user;

import com.pand.model.BaseObject;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.List;

/**
 * 
 * @ClassName: User 
 * @Description: 用户
 *
 */
@Entity
@Table(name = "SYS_USER")
@SequenceGenerator(name = "SeqUser", sequenceName = "SEQ_USER", allocationSize = 1)
public class User extends BaseObject{
	
	/** 
	 * @Fields serialVersionUID : 
	 */ 
	private static final long serialVersionUID = 1L;
	
	/**
	 * 主键
	 */
	private Long id;
	
	/**
	 * 创建时间
	 */
	private Timestamp createTime;
	
	/**
	 * 密码
	 */
	private String password;
	
	/**
	 * 用户名
	 */
	private String userName;
	
	/**
	 * 登陆名
	 */
	private String loginID;
	
	/**
	 * 最后一次登录时间
	 */
	private Timestamp lastLoginTime;
	
	/**
	 * 用户手机号
	 */
	private String userPhone;
	
	/**
	 * 邮箱
	 */
	private String userMail;
	
	/**
	 * 组织机构代码
	 */
	private Long orgID;
	
	/**
	 * 职位
	 */
	private String position;
	
	/**
	 * 
	 */
	private String positionName;
	
	/**
	 * 角色列表
	 */
	private List<Role> roles;

	@Id
	@GeneratedValue(generator = "SeqUser")
	@Column(name = "ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "CREATE_TIME")
	public Timestamp getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}

	@Column(name = "PASSWORD")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "USERNAME")
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Column(name = "LOGIN_ID")
	public String getLoginID() {
		return loginID;
	}

	public void setLoginID(String loginID) {
		this.loginID = loginID;
	}

	@Column(name = "LAST_LOGIN_TIME")
	public Timestamp getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(Timestamp lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	@Column(name = "USER_PHONE")
	public String getUserPhone() {
		return userPhone;
	}

	public void setUserPhone(String userPhone) {
		this.userPhone = userPhone;
	}

	@Column(name = "USER_MAIL")
	public String getUserMail() {
		return userMail;
	}

	public void setUserMail(String userMail) {
		this.userMail = userMail;
	}

	//@OneToMany(mappedBy = "userId")
	@ManyToMany(
			targetEntity=com.pand.model.user.Role.class,
			cascade ={CascadeType.PERSIST,CascadeType.MERGE}, 
			fetch=FetchType.LAZY )
	@JoinTable(name="SYS_USER_ROLE", 
			   joinColumns={@JoinColumn(name="USER_ID")}, 
			   inverseJoinColumns={@JoinColumn(name="ROLE_ID")})
	public List<Role> getRoles() {
		return roles;
	}
	
	

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	
	@Column(name = "ORG_ID")
	public Long getOrgID() {
		return orgID;
	}

	public void setOrgID(Long orgID) {
		this.orgID = orgID;
	}

	@Column(name = "POSITION")
	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	@Transient
	public String getPositionName() {
		return positionName;
	}

	public void setPositionName(String positionName) {
		this.positionName = positionName;
	}
	
}
